import gc
import psutil
import time
import threading
'''
内存监控
'''

def monitor(pid,function_type,interval,count):
    time.time()
    process = psutil.Process(pid)
    if function_type == 1:
        get_memory_info(process,interval,count)
    elif function_type == 2:
        get_thread_info(process,interval,count)
    elif function_type == 3:
        get_python_gc_info(interval,count)

def get_memory_info(process,interval,count):
    print('--memory--')
    print('vms\trss')
    while count > 0:
        memory = process.memory_info()
        print(memory.vms, '\t', memory.rss)
        count = count-1
        time.sleep(interval)

def get_thread_info(process,interval,count):
    print('--thread--')
    print('id\tname\tstatus')
    while count > 0:
        threads = process.threads()
        for thread in threads:
            thread_id = thread.id
            threading.Thread
        #print(len(threads))
        count = count - 1
        time.sleep(interval)

def get_python_gc_info(interval,count):
    while count > 0:
        # 获取垃圾回收器的统计信息
        gc_stats = gc.get_stats()
        # 获取垃圾回收器当前的阈值
        gc_threshold = gc.get_threshold()

        # 获取垃圾回收器当前的阈值设置
        gc_threshold_setting = gc.get_threshold()

        # 获取垃圾回收器是否启用了调试标志
        gc_debug_flag = gc.isenabled()

        # 获取当前的垃圾回收计数
        gc_count = gc.get_count()

        # 输出监控信息
        print("垃圾回收器统计信息:", gc_stats)
        print("垃圾回收器当前阈值:", gc_threshold)
        print("垃圾回收器阈值设置:", gc_threshold_setting)
        print("垃圾回收器调试标志:", gc_debug_flag)
        print("当前垃圾回收计数:", gc_count)
        count = count - 1
        time.sleep(interval)
monitor(13464,3,3,20)